package com.mediastory.spsserver.verMngr.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mediastory.spsserver.verMngr.domain.VerMngr;
import com.mediastory.spsserver.verMngr.service.VerMngrSvc;

/**
 * @author Jaewon Choi
 */

@Controller
@RequestMapping("/verMngr")
public class VerMngrCtrl {
	
	private final Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private MessageSourceAccessor messages;
	
	@Autowired
	private VerMngrSvc verMngrSvc;

	/**
	 * 등록 폼
	 * */
	@RequestMapping(value={"/form.do"})
	public Map<String, Object> form(HttpServletRequest request) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Map<String, Object> condition = new HashMap<String, Object>();
		resultMap.put("verMngrList", verMngrSvc.findbyList(condition));

		return resultMap;
	}
	
	/**
	 * 등록
	 * */
	@RequestMapping(value={"/submit.do"}, method=RequestMethod.POST)
	public String submit(VerMngr verMngr, HttpSession session, HttpServletRequest request) throws Exception {
		String userId = (String)session.getAttribute("userId");
		String ip = request.getRemoteAddr();
		
		verMngr.setCreatedId(userId);
		verMngr.setCreatedIp(ip);
		verMngrSvc.add(verMngr);

		return "verMngr/result";
	}

}